package com.glance.browser.domain;

import java.io.Serializable;
import java.sql.Blob;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name="Author")
public class Author implements Serializable {

	private static final long serialVersionUID = 2513780906808312065L;

	// Persistent Fields:
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "author_id")
    private Long id;
    
    @Column(name="Photo")
    @Lob
    private Blob photo;
    
    @Column(name = "first_name", length = 45)
    @Size(min=1)
    private String firstName;
    
    @Column(name = "last_name", length = 45)
    @Size(min=1)
    private String lastName;
    
    @Column(name = "nationality", length = 45)
    private String nationality;
    
    @Column(name = "profession", length = 45)
    private String profession;
    
    @Column(name = "birth_date")
	@Temporal(TemporalType.DATE)
	@DateTimeFormat(style = "M-")
	private Date birthDate;
    
    @Column(name = "death_date")
	@Temporal(TemporalType.DATE)
	@DateTimeFormat(style = "M-")
	private Date deathDate;
    
    // Constructors:
    public Author() {
    }

    public Author(String firstName, String lastName, String nationality, String profession, Date birthDate, Date deathDate, Blob photo) {
       this.firstName = firstName;
       this.lastName = lastName;
       this.setNationality(nationality);
       this.setProfession(profession);
       this.setBirthDate(birthDate);
       this.setDeathDate(deathDate);
       this.setPhoto(photo);
    }

    public Author(String firstName, String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}

	// String Representation:
    @Override
    public String toString() {
        return lastName + ", " + firstName;
    }

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Blob getPhoto() {
		return photo;
	}

	public void setPhoto(Blob photo) {
		this.photo = photo;
	}

	public String getNationality() {
		return nationality;
	}

	public void setNationality(String nationality) {
		this.nationality = nationality;
	}

	public String getProfession() {
		return profession;
	}

	public void setProfession(String profession) {
		this.profession = profession;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public Date getDeathDate() {
		return deathDate;
	}

	public void setDeathDate(Date deathDate) {
		this.deathDate = deathDate;
	}
}
